<template>
  <div class="areaScreen">
    <div class="areaScreen-one">
      <div class="areaScreen-one-text">
        地区
      </div>
      <div class="areaScreen-one-all" :class="{active:active==='全部'}" @click="areaAll">
        全部
      </div>
      <div v-if="areaScreen.length" class="areaScreen-one-item-wrap">
        <div v-for="item in areaScreenOne" :key="item.name" class="areaScreen-one-item" :class="{active:active===item.name}" @click="tab(item)">
          {{ item.name }}
        </div>
      </div>
    </div>
    <div class="areaScreen-two" :style="{'height': autoHeight}">
      <div v-for="item in areaScreen" :key="item.name" class="areaScreen-two-item" :class="{active:active===item.name}" @click="tab(item)">
        {{ item.name }}
      </div>
      <div v-if="areaScreen.length" class="areaScreen-two-item more" @click="showMore">
        <span>{{ moretext }}</span>
        <img src="@/assets/img/right-icon.png" alt="" class="arrow" :style="`transform: rotate(${deg}deg);`">
      </div>
    </div>
  </div>
</template>
<script>
import { getCityData } from '@/api/areaScreen'
export default {
  props: {
    fatherActive: {
      type: String,
      default: '全部'
    }
  },
  data() {
    return {
      areaScreenOne: [],
      areaScreen: [],
      active: '全部',
      autoHeight: '35px',
      moretext: '更多',
      deg: 90
    }
  },
  computed: {

  },
  created() {
    this.getCity()
    if (this.fatherActive !== '') {
      this.active = this.fatherActive
    }
  },
  mounted() {

  },
  methods: {
    getCity() {
      getCityData().then((res) => {
        this.areaScreenOne = res.data[0].child
        this.areaScreen = res.data.splice(1)
      })
    },
    tab(i) {
      this.active = i.name
      this.$emit('city', i.name)
    },
    areaAll() {
      this.active = '全部'
      this.$emit('city', '')
    },
    showMore() {
      if (!this.isShowMore) {
        this.autoHeight = 'auto'
        this.moretext = '收起'
        this.deg = -90
      } else {
        this.autoHeight = '35px'
        this.moretext = '更多'
        this.deg = 90
      }
      this.isShowMore = !this.isShowMore
    }
  }
}
</script>
<style scoped lang="scss">
.areaScreen {
  width: 1190px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  margin-top: 10px;
  padding-bottom: 15px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  .active {
    color: rgba(80, 76, 255, 1) !important;
  }
  .areaScreen-one {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid rgba(240, 240, 240, 1);
    display: flex;
    align-items: center;
    .areaScreen-one-text {
      margin-left: 30px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: rgba(153, 153, 153, 1);
      line-height: 20px;
    }
    .areaScreen-one-all {
      margin-left: 30px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
    }
    .areaScreen-one-all:hover {
      cursor: pointer;
    }
    .areaScreen-one-item-wrap {
      display: flex;
      .areaScreen-one-item {
        margin-left: 30px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(102, 102, 102, 1);
        line-height: 20px;
      }
      .areaScreen-one-item:hover {
        cursor: pointer;
      }
    }
  }
  .areaScreen-two {
    height: 35px;
    display: flex;
    flex-wrap: wrap;
    margin-left: 88px;
    padding-right: 110px;
    position: relative;
    overflow: hidden;
    .more {
      position: absolute;
      right: 0;
      margin-right: 80px;
      display: flex;
      align-items: center;
      span {
        margin-right: 5px;
      }
      .arrow {
        display: block;
        width: 6px;
        margin-right: -8px;
      }
    }
  }
  .areaScreen-two-item {
    margin-right: 30px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
    line-height: 20px;
    margin-top: 15px;
  }
  .areaScreen-two-item:hover {
    cursor: pointer;
  }
}
</style>
